#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
using namespace std;
char s[100005];
string f[30],s1,s2;
int i,j,i1,j1,l,ans,h[100005][10],a[30][30][10][10];
string ch(string ss,int x)
{
    if (x==1) return ss;
    if (x==2) return ""+ss[0]+ss[2]+ss[1];
    if (x==3) return ""+ss[1]+ss[0]+ss[2];
    if (x==4) return ""+ss[1]+ss[2]+ss[0];
    if (x==5) return ""+ss[2]+ss[0]+ss[1];
    return ""+ss[2]+ss[1]+ss[0];
}
int main()
{
    //freopen("in","r",stdin);
    scanf("%s",s);
    f['Y'-'A']="QQQ";f['V'-'A']="QQW";f['G'-'A']="QQE";f['C'-'A']="WWW";f['X'-'A']="QWW";
    f['Z'-'A']="WWE";f['T'-'A']="EEE";f['F'-'A']="QEE";f['D'-'A']="WEE";f['B'-'A']="QWE";
    for(i=1;i<=25;i++)
    if (f[i]!="")
    for(j=1;j<=25;j++)
    if (f[j]!="")
    {
        for(i1=1;i1<=6;i1++)
        for(j1=1;j1<=6;j1++)
        {
            s1=ch(f[i],i1);
            s2=ch(f[j],j1);
            if (s1[0]==s2[0]&&s1[1]==s2[1]&&s1[2]==s2[2]) ans=0;
            else if (s1[0]==s2[1]&&s1[1]==s2[2]) ans=1;
            else if (s1[0]==s2[2]) ans=2; else   ans=3;
            a[i][j][i1][j1]=ans;
        }
    }
	while(~scanf("%s",s))
	{
		l=strlen(s);
		for(i=1;i<l;i++)
			for(j=1;j<=6;j++)
				h[i][j]=123456789;
		for(i=1;i<l;i++)
			for(i1=1;i1<=6;i1++)
				for(j1=1;j1<=6;j1++)
					h[i][i1]=min(h[i][i1],h[i-1][j1]+a[s[i]-'A'][s[i-1]-'A'][i1][j1]);
		ans=123456789;
		for(i=1;i<=6;i++)
			ans=min(ans,h[l-1][i]);
		printf("%d\n",ans+l+3);
	}
    return 0;
}
